﻿using System;
using System.Collections.Generic;
using System.Messaging;
using System.Text;

namespace qcreate
{
	class Program
	{
		static void Main(string[] args)
		{
			if (args.Length == 0)
			{
				Console.Error.WriteLine("USAGE: qcreate .\\private$\\queuename");
				return;
			}

			string path = args[0];

			MessageQueue q = null;
			
			if (!MessageQueue.Exists(path))
			{
				q = MessageQueue.Create(path);
			}
			else
			{
				Console.WriteLine("Already exists. Update permissions");
				q = new MessageQueue(path);
			}

			Console.WriteLine("AccessMode:{0} CanRead:{1} CanWrite:{2}", q.AccessMode, q.CanRead ? "r" : "-", q.CanWrite ? "w" : "-", q.FormatName);
			q.SetPermissions("ANONYMOUS LOGON", MessageQueueAccessRights.FullControl);
			q.SetPermissions("Everyone", MessageQueueAccessRights.FullControl);
		}
	}
}
